package cn.bonoon.controllers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.bonoon.kernel.support.PasswordVerifier;
import cn.bonoon.kernel.util.MD5Util;

/**
 * 这里是支持一些系统开发时或某些配置，接口调用的测试页面；
 * 
 * @author jackson
 *
 */
@Controller
@RequestMapping("comm/test")
public class CommonTestController {

	@Autowired
	private PasswordVerifier passwordVerifier;
	
	@ResponseBody
	@RequestMapping("password/encrypt.json")
	public Object activity(@RequestParam("p") String p){
		String md5 = MD5Util.getMD5(p);
		String pwd = passwordVerifier.encode(md5);
		return pwd;
	}

	@ResponseBody
	@RequestMapping("check/md5.json")
	public Object checkMd5(
			@RequestParam("m") String m, 
			@RequestParam("p") String p){
		String md5 = MD5Util.getMD5(p);
		return md5.equals(m);
	}

	@ResponseBody
	@RequestMapping("check/password.json")
	public Object checkPwd(
			@RequestParam("e") String e, 
			@RequestParam("p") String p){
		String md5 = MD5Util.getMD5(p);
		return passwordVerifier.matches(md5, e);
	}
}
